# _*_coding:utf-8_*_
__author__ = 'gerry'

# read the file
fw = file("py_home_work.csv", "r")
for line in fw.readlines():
    print line,
fw.close()

# write the file
fw = file("test.txt", "w")
# if file exists,then will cover the content,or create a new file
fw.write("this is the first line!\n")
fw.write("this is the second line!\n")
fw.write("this is the third line!\n")

# append
fw = file("test.txt", "a")
fw.write("this is the appending part ,I am different\n")
fw.write("this is the appending part ,I am different rterttoo\n")

fw.close()
# read and write :r+ w+

f2 = file("test.txt", "r+")
print "first line:", f2.readline(),
print "second line:", f2.readline(),
f2.write("change third line")
print "third line:", f2.readline()
print f2.tell()
for line in f2.xreadlines():
    print line,


f2.close()





















